<?php

namespace App\Http\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;


class Boat extends Base
{
    protected $table = 'gift_bag_intimacy_log';

    public function __construct(array $attributes = [])
    {
        parent::__construct($this->table, $attributes);
    }
    //兑换碎片
    public function createSendChipLog($api_data)
    {
        $data['user_id'] = $api_data['user_id'];
        $data['common'] = $api_data['common'];
        $data['uncommon'] = $api_data['uncommon'];
        $data['purpose'] = $api_data['purpose'];
        $data['type'] = $api_data['type'] + 1; // 2增加 1减少
        $data['created_at'] = $data['updated_at'] = date_ymd();
        $res = DB::table('boat_user_chip_log')->insertGetId($data);
        if (!$res) {
            write_log('boatChip', 'createLogError', $data);//积分日志赠送失败
        }
        return true;
    }
    //兑换抽奖券
    public function createTicketLog($api_data)
    {
        $data['user_id'] = $api_data['user_id'];
        $data['ticket'] = $api_data['ticket'];
        $data['diamion'] = $api_data['diamion'];
        $data['from'] = $api_data['from'];
        $data['type'] = $api_data['type'] + 1; // 2增加 1减少
        $data['created_at'] = $data['updated_at'] = date_ymd();
        $res = DB::table('boat_user_ticket_log')->insertGetId($data);
        if (!$res) {
            write_log('boatTicket', 'createLogError', $data);//积分日志赠送失败
        }
        return true;
    }

    //差价log 库 type ; 1送礼榜 2 收礼 3 积分 4亲密值
    public function creaeteLog($user_id, $type, $old_num, $new_num)
    {
        $data['user_id'] = $user_id;
        $data['type'] = $type;
        $data['old_num'] = $old_num;
        $data['new_num'] = $new_num;
        $data['created_at'] = $data['updated_at'] = date_ymd();
        $res = DB::table('gift_bag_edit_score_intimacy_log')->insert($data);
        if (!$res) {
            write_log('newIntimacy', 'createLogError', $data);//积分日志赠送失败
        }
        return true;
    }


}